package students.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import students.db.DbConnection;
import students.po.AdminDo;
import students.service.AdminService;

public class AdminServiceImpl implements AdminService{

	@Override
	public boolean validateAdmin(AdminDo adminDo) {
		String userName = adminDo.getUserName();
		String pwdParam = adminDo.getPwd();
		
		String sql = "SELECT pwd FROM manager WHERE user_name = ?";
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			conn = DbConnection.getConnection();
			if(conn ==null) {
				return false;
			}
			ps = conn.prepareStatement(sql);
			ps.setString(1, adminDo.getUserName());
			rs = ps.executeQuery();
			while(rs.next()) {
				String pwd = rs.getString(1);
				if(adminDo.getPwd().equals(pwd)) {
					return true;
				}
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			DbConnection.close(ps,null);
		}
		return false;
	}

}
